﻿package src.utils 
{
	import src.debug.MonsterDebugger;
	import src.data.ConfigData;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	
	/**
	 * ...
	 * @author hrh - 2009
	 */
	
	public class StatTracker
	{
		public function StatTracker() {}
		
		public static function sendStats(track:String,config:ConfigData):void
		{
			if (config.trackingEnabled)
			{
				var url:String = config.statTrackerUrl + track + '&visitor=' + config.visitor + '&session=' + config.session + '&duration=' + config.duration;
				
				MonsterDebugger.trace(StatTracker, url);
				
				post(url);
			}
		}
		
		private static function post(url:String):void
		{
			var request:URLRequest;
			var loader:URLLoader = new URLLoader();		
			
			loader.addEventListener(Event.COMPLETE, completeHandler);    
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			
			request = new URLRequest(url);
			request.method = URLRequestMethod.POST;
			
			//send data
			try
			{
				loader.load(request);
			}
			catch (e:Error)
			{
				trace(e.message);
			}
		}
		
		private static function completeHandler(e:Event):void
		{
			
		}
		
		private static function ioErrorHandler(e:IOErrorEvent):void
		{
			
		}
	}
}